#include "../AssemblyTemplate.h"
#include <assert.h>

namespace ECS
{
	void AssemblyTemplate::apply( Assembly* assembly )
	{
		assert(assembly != nullptr);

		std::vector<std::pair<IComponentTemplate*, Component*> > components;

		for (auto it = _components.begin(); it != _components.end(); ++it)
		{
			IComponentTemplate* factory = *it;
			Component* component = factory->create();
			assembly->addComponent(component);
			components.push_back(std::make_pair(factory, component));
		}

		for (auto it = components.begin(); it != components.end(); ++it)
		{
			IComponentTemplate* factory = it->first;
			Component* component = it->second;
			factory->afterInit(component);
		}
	}

	void AssemblyTemplate::addComponent( IComponentTemplate* item )
	{
		_components.push_back(item);
	}

}